/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.business.account.core.repository.mapper;

import info.peigen.hotpot.business.account.core.repository.entity.AccountTransLogEntity;
import info.peigen.hotpot.business.account.facade.enums.AccountTransCode;
import info.peigen.hotpot.component.data.repository.beetlsql.mapper.AbstractBeetlSqlMapper;
import org.beetl.sql.mapper.annotation.Select;
import org.beetl.sql.mapper.annotation.Sql;
import org.beetl.sql.mapper.annotation.Template;
import org.beetl.sql.mapper.annotation.Update;

import java.util.List;

/**
 * <b>(AccountTransLogMapper)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2021/8/12
 */
@SuppressWarnings("AlibabaAbstractMethodOrInterfaceMethodMustUseJavadoc")
public interface AccountTransLogMapper extends AbstractBeetlSqlMapper<AccountTransLogEntity> {

    @Sql("select * from account_trans_log where trans_log_id = ?")
    @Select
    AccountTransLogEntity findByTransLogId(String transLogId);

    @Sql("select * from account_trans_log where trade_id = ?")
    @Select
    List<AccountTransLogEntity> findByTradeId(String tradeId);

    @Sql("select * from account_trans_log where trade_id = ? and trans_code = ?")
    @Select
    AccountTransLogEntity findByTradeIdAndTransCode(String tradeId, AccountTransCode transCode);

    @Sql("delete from account_trans_log where trans_log_id = ?")
    @Update
    void deleteByTransLogId(String transLogId);

    @Sql("delete from account_trans_log where trade_id = ?")
    @Update
    void deleteByTradeId(String tradeId);

    @Template("delete from account_trans_log where debit_account_id=#{accountId} or credit_account_id=#{accountId}")
    @Update
    void deleteByAccountId(String accountId);
}